home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Threads.h
-
- Contains: External Interface to Thread Manager
-
- Written by: David Harrison, Eric Anderson
-
- Copyright: © 1991-1993 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 1/28/93 ewa Made all error codes end with 'Err'. All errors are now
- of the form: xxxErr
- 1/27/93 ewa Added GetDefaultThreadStackSize & ThreadCurrentStackSpace
- information routines
- 1/26/93 ewa Added SetThreadStateEndCritical routine to help thread synchronization
- 1/13/93 ewa Put preemption quantum adjustment support into private header
- 12/23/92 ewa Added support for system wide preemption quantum adjustment
- 12/22/92 ewa User must now specify the required stack to use for their threads,
- however, if they pass in zero we will provide them with a default size
- 12/22/92 ewa Added thread termination proc support
- fixed param count in interface glue
- 12/21/92 ewa Added kFPUNotNeeded as a thread option
- 7/31/92 ewa Added Gestalt selector constants.
- <4> 7/29/92 ewa changed InterruptedSyncThreadID to InterruptedCoopThreadID.
- <3> 7/15/92 ewa Added calls to support interrupt time thread state manipulation.
- <2> 7/14/92 ewa Add callbacks to the debugger for birth, death and schedule.
- <1> 7/13/92 ewa added real error nums, changed CreateThreads to CreateThreadPool,
- changed kToolbox & kAsync thread defines to be kCoop & kPremp.
- <0> 4/19/91 DFH New Today.
-
- */
-
- #ifndef __THREADS__
- #define __THREADS__
-
- #include <Memory.h>
-
- /* Thread Gestalt Selectors */
- enum {
- #define gestaltThreadAttr 'thds' /* Thread Manager attributes */
-
- gestaltThreadsPresent = 0 /* bit true if Thread Mgr is present */
- };
-
- /* Thread states */
- typedef unsigned short ThreadState;
- #define kReadyThreadState ((ThreadState) 0)
- #define kStoppedThreadState ((ThreadState) 1)
- #define kRunningThreadState ((ThreadState) 2)
-
- /* Thread environment characteristics */
- typedef void* ThreadTaskRef;
-
- /* Thread characteristics */
- typedef unsigned long ThreadStyle;
- #define kCooperativeThread (1<<0)
- #define kPreemptiveThread (1<<1)
-
- /* Thread identifiers */
- typedef unsigned long ThreadID;
- #define kNoThreadID ((ThreadID) 0)
- #define kCurrentThreadID ((ThreadID) 1)
- #define kApplicationThreadID ((ThreadID) 2)
-
- /* Options when creating a thread */
- typedef unsigned long ThreadOptions;
- #define kNewSuspend (1<<0)
- #define kUsePremadeThread (1<<1)
- #define kCreateIfNeeded (1<<2)
- #define kFPUNotNeeded (1<<3)
-
- /* Information supplied to the custom scheduler */
- typedef struct SchedulerInfoRec {
- unsigned long InfoRecSize;
- ThreadID CurrentThreadID;
- ThreadID SuggestedThreadID;
- ThreadID InterruptedCoopThreadID;
- } SchedulerInfoRec, *SchedulerInfoRecPtr;
-
- /* Prototype for thread's entry (main) routine */
- typedef pascal void * (ThreadEntryProc)(void *threadParam);
- typedef ThreadEntryProc *ThreadEntryProcPtr;
-
- /* Prototype for custom thread scheduler routine */
- typedef pascal ThreadID (ThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
- typedef ThreadSchedulerProc *ThreadSchedulerProcPtr;
-
- /* Prototype for custom thread switcher routine */
- typedef pascal void (ThreadSwitchProc)(ThreadID threadBeingSwitched, void *switchProcParam);
- typedef ThreadSwitchProc *ThreadSwitchProcPtr;
-
- /* Prototype for thread termination notification routine */
- typedef pascal void (ThreadTerminationProc)(ThreadID threadTerminated, void *terminationProcParam);
- typedef ThreadTerminationProc *ThreadTerminationProcPtr;
-
- /* Prototype for debugger NewThread notification */
- typedef pascal void (DebuggerNewThreadProc)(ThreadID threadCreated);
- typedef DebuggerNewThreadProc *DebuggerNewThreadProcPtr;
-
- /* Prototype for debugger DisposeThread notification */
- typedef pascal void (DebuggerDisposeThreadProc)(ThreadID threadDeleted);
- typedef DebuggerDisposeThreadProc *DebuggerDisposeThreadProcPtr;
-
- /* Prototype for debugger schedule notification */
- typedef pascal ThreadID (DebuggerThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
- typedef DebuggerThreadSchedulerProc *DebuggerThreadSchedulerProcPtr;
-
- /* Errors */
- enum {
- threadTooManyReqsErr = -617,
- threadNotFoundErr = -618,
- threadProtocolErr = -619
- };
-
- /* Thread Manager routines */
- pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
- = {0x303C,0x0501,0xABF2};
-
- pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
- = {0x303C,0x0402,0xABF2};
-
- pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
- = {0x303C,0x0413,0xABF2};
-
- pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
- = {0x303C,0x0414,0xABF2};
-
- pascal OSErr NewThread( ThreadStyle threadStyle,
- ThreadEntryProcPtr threadEntry,
- void *threadParam,
- Size stackSize,
- ThreadOptions options,
- void **threadResult,
- ThreadID *threadMade)
- = {0x303C,0x0E03,0xABF2};
-
- pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
- = {0x303C,0x0504,0xABF2};
-
- pascal OSErr YieldToThread(ThreadID suggestedThread)
- = {0x303C,0x0205,0xABF2};
-
- pascal OSErr YieldToAnyThread(void)
- = {0x42A7,0x303C,0x0205,0xABF2};
-
- pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
- = {0x303C,0x0206,0xABF2};
-
- pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
- = {0x303C,0x0407,0xABF2};
-
- pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
- = {0x303C,0x0508,0xABF2};
-
- pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
- = {0x303C,0x0512,0xABF2};
-
- pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
- = {0x303C,0x0209,0xABF2};
-
- pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
- = {0x303C,0x070A,0xABF2};
-
- pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
- = {0x303C,0x0611,0xABF2};
-
- pascal OSErr ThreadBeginCritical(void)
- = {0x303C,0x000B,0xABF2};
-
- pascal OSErr ThreadEndCritical(void)
- = {0x303C,0x000C,0xABF2};
-
- pascal OSErr SetDebuggerNotificationProcs ( DebuggerNewThreadProcPtr notifyNewThread,
- DebuggerDisposeThreadProcPtr notifyDisposeThread,
- DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
- = {0x303C,0x060D,0xABF2};
-
- pascal OSErr GetThreadCurrentTaskRef (ThreadTaskRef *threadTRef)
- = {0x303C,0x020E,0xABF2};
-
- pascal OSErr GetThreadStateGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
- = {0x303C,0x060F,0xABF2};
-
- pascal OSErr SetThreadReadyGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToSet)
- = {0x303C,0x0410,0xABF2};
-
-
- #endif /* __THREADS__ */
-